<template>
  <!-- 修改窗口 -->
  <a-modal v-model:visible="visible" title="修改用户信息" @ok="execUpd">
    <a-form
      ref="fromRef"
      :model="updObj"
      :label-col="{ span: 5 }"
      :wrapper-col="{ span: 14 }"
    >
      <a-form-item label="账号">
        <a-input v-model:value="updObj.u_id" disabled />
      </a-form-item>
      <a-form-item label="姓名">
        <a-input v-model:value="updObj.u_name" />
      </a-form-item>
      <a-form-item label="性别">
        <a-radio-group v-model:value="updObj.u_sex">
          <a-radio value="1">男</a-radio>
          <a-radio value="2">女</a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="出生日期">
        <a-date-picker v-model:value="updObj.u_birth" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
//修改
import { ref, reactive } from "vue";
import { put, tip } from "@/common";

export default {
  
  setup(props, { emit }) {
    const fromRef = ref();
    const updObj = reactive({
      u_id: "",
      u_name: "",
      u_sex: "",
      u_birth:""
    });
    const visible = ref(false);

    const open = (rec) => {
      updObj.u_id = rec.u_id;
      updObj.u_name = rec.u_name;

      updObj.u_sex = rec.u_sex && String(rec.u_sex);
      updObj.u_birth = rec.u_birth;
      visible.value = true;
    };

    const execUpd = () => {
      //执行新增
      put("/security/user", updObj).then((res) => {
        emit('ok');
        updObj.u_id="";
        updObj.u_name= "";
        updObj.u_sex = "";
        updObj.u_birth = "";
        visible.value = false;
        tip.success("修改用户成功！");        
      });

    };

    return {
      updObj,
      visible,
      execUpd,
      open,
      fromRef,
    };
  },
};
</script>
<style scoped>
</style>